package com.xiguaji.tiktok.task.keyword;

import com.gugee.tiktok.common.model.mysql.BloggerLog;
import com.xiguaji.boot.toolkit.JsonUtil;
import com.xiguaji.tiktok.task.common.job.TaskParam;
import com.xiguaji.tiktok.task.keyword.service.KeywordService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class KeywordTask {

    @Autowired
    KeywordService keywordService;


    /**
     * 发送采集评论的消息
     * @param param
     * @return
     */
    @XxlJob("sendKeyword2kafkaHandler")
    public ReturnT<String> sendKeyword2kafkaHandler(String param) {
        long start = System.currentTimeMillis();
        try {
            log.info("开始启动消息投递任务: params={}", param);
            XxlJobLogger.log("开始启动消息投递任务: params={}", param);
            TaskParam jobParam = JsonUtil.jsonParse(TaskParam.class, param);
            int bloggerLogType = BloggerLog.BloggerLogType.SEND_KEYWORD_2_KAFKA.getValue();
            keywordService.send(bloggerLogType,"sendKeyword2kafkaHandler",jobParam);
            return ReturnT.SUCCESS;
        } catch (Exception ex) {
            XxlJobLogger.log(ex);
            log.error(ex.getMessage());
            return ReturnT.FAIL;
        }finally {
            log.info("投递结束  end cost total={},", (System.currentTimeMillis() - start) / 1000);
            XxlJobLogger.log("投递结束  end cost total={}, params={}", (System.currentTimeMillis() - start) / 1000,param);
        }
    }

}


